//
//  HNSH_ConfirmOrderBottomView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/26.
//

#import "HNSH_ConfirmOrderBottomView.h"

@interface HNSH_ConfirmOrderBottomView ()

/* button */
@property (nonatomic, strong) UIButton *button;

/* moneyDesLabel */
@property (nonatomic, strong) UILabel *moneyDesLabel;
/* moneyLabel */
@property (nonatomic, strong) UILabel *moneyLabel;

@end

@implementation HNSH_ConfirmOrderBottomView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appWhiteLabelColor];
        [self configUI];
    }
    return self;
}

- (void)setMoneyString:(NSString *)moneyString {
    _moneyString = moneyString;
    self.moneyLabel.text = [NSString stringWithFormat:@"%.2f",[moneyString doubleValue]];
}

- (void)configUI {
    [self addSubview:self.button];
    [self addSubview:self.moneyDesLabel];
    [self addSubview:self.moneyLabel];
    
    [self.moneyDesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(7);
        make.height.mas_equalTo(16);
    }];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(23);
        make.height.mas_equalTo(20);
    }];
    
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(7);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(102);
    }];
    
    WeakSelf(weakSelf);
    [[self.button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.clickBlock) {
            weakSelf.clickBlock();
        }
    }];
}

#pragma mark lazy
- (UIButton *)button {
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button setTitle:@"提交订单" forState:UIControlStateNormal];
        [_button setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _button.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        _button.backgroundColor = [UIColor appGreenColor];
        _button.layer.cornerRadius = 20.0f;
        _button.layer.masksToBounds = YES;
    }
    return _button;
}

- (UILabel *)moneyDesLabel{
    if (!_moneyDesLabel) {
        _moneyDesLabel = [UILabel new];
        _moneyDesLabel.text = @"可得购物值：";
        _moneyDesLabel.textColor = [UIColor appGrayLabelColor];
        _moneyDesLabel.font = [UIFont systemFontOfSize:12];
    }
    return _moneyDesLabel;
}

- (UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel = [UILabel new];
        _moneyLabel.text = @"";
        _moneyLabel.textColor = [UIColor appBlackLabelColor];
        _moneyLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _moneyLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
